<?php
/**
 * Created by PhpStorm.
 * User: 67569
 * Date: 2018/5/3
 * Time: 18:29
 */

require_once('pdo.php');
date_default_timezone_set('PRC');
session_start();
$newsContent = $_POST['field2'];
$newsTitle = $_POST['newsTitle'];
$newsAuthor = $_POST['newsAuthor'];
$newsType=$_POST['newsType'];
$nowDate = date('Y-m-d H:i:s');
$newsContentRe=str_replace("'","\'",$newsContent);


if (($newsContent <> '<p><br></p>') && ($newsTitle <> '')) {
    if(strpos($newsContent,'iframe')!== false){
        $sql = "insert into news_info (news_title, news_content, create_time,news_author,news_type,change_time)
values ('{$newsTitle}','{$newsContentRe}','{$nowDate}','{$newsAuthor}','{$newsType}','{$nowDate}')";
        var_dump($sql);
        $pdo->exec($sql);
    echo "<script>alert('发布成功（包含视频）！');history.back()</script>";
    }else{
        $sql = "insert into news_info (news_title, news_content, create_time,news_author,news_type,change_time)
values ('{$newsTitle}','{$newsContent}','{$nowDate}','{$newsAuthor}','{$newsType}','{$nowDate}')";
        var_dump($sql);
        $pdo->exec($sql);
    echo "<script>alert('发布成功！');history.back()</script>";
    }
} else {
    echo "<script>alert('发布失败，请填写新闻标题和新闻正文内容');history.back();</script>";
}
?>


